let delayHideLoadingTimer = null;
const LOCK = {
  confirm: false
}
const showLoading = uni.showLoading;
const hideLoading = uni.hideLoading;
// const redirectTo=uni.redirectTo;
uni.toast = (title) => {
  return new Promise(resolve => {
    const duration = 1000;
    uni.showToast({
      icon: 'none',
      title,
      duration
    });
    setTimeout(() => {
      resolve()
    }, duration)
  })
}
uni.showLoading = (title = '加载中...') => {
  delayHideLoadingTimer && clearTimeout(delayHideLoadingTimer);
  showLoading({
    mask: true,
    title
  });
}
uni.hideLoading = (delay = 300) => {
  delayHideLoadingTimer && clearTimeout(delayHideLoadingTimer)
  return new Promise(resolve => {
    delayHideLoadingTimer = setTimeout(() => {
      hideLoading();
      resolve(true)
    }, delay)
  })
}
// uni.redirectTo=(pageObj)=>{

// }
uni.confirm = (content, options = {}) => {
  if (LOCK.confirm){return Promise.reject();}
  LOCK.confirm = true;
  setTimeout(() => {
    LOCK.confirm = false
  }, 300);
  return new Promise((resolve, reject) => {
    uni.showModal({
      content,
      ...options,
      confirmColor: "#BF375A",
      complete: ({
        confirm
      }) => {
        confirm ? resolve() : reject()
      }
    })
  })
}
uni.sleep = (time) => {
  return new Promise(resolve => {
    console.log('degn等待', time)
    setTimeout(() => {
      resolve()
      console.log('释放');
    }, time)
  })
}
uni.reLaunchOrderList = (path) => {
  uni.reLaunch({
    url: "/pages/order/order-list?targetUrl=" + encodeURIComponent(path)
  })
  // (getCurrentPages().findIndex(item =>
  //   item.__route__ === "pages/order/order-list"
  // ) === -1) && uni.reLaunch({
  //   url: "/pages/order/order-list"
  // })
}
